import { registerMicroApps, start } from 'qiankun';

const microAppLoaded = new CustomEvent('micro-app-loaded', {
	detail: {
		loading: false
	}
});

const triggerMicroEvent = (loading: boolean) => {
	microAppLoaded.detail.loading = loading;
	window.dispatchEvent(microAppLoaded);
	return Promise.resolve();
};

export const microAppsRoute = [
	{
		name: 'chart-sub',
		entry: '//localhost:5173',
		container: '#container',
		activeRule: '/chart',
		props: {}
	},
	{
		name: 'gis-sub',
		entry: '//localhost:5174',
		container: '#container',
		activeRule: '/gis',
		props: {}
	},
	{
		name: 'other-sub',
		entry: '//localhost:5176',
		container: '#container',
		activeRule: '/other',
		props: {}
	}
];

registerMicroApps(microAppsRoute, {
	beforeLoad: () => triggerMicroEvent(true),
	afterMount: () => triggerMicroEvent(false)
});

start({ prefetch: false });
